package com.xixi.canal.client.starter.config;

import com.xixi.canal.client.support.ConfigProperties;
import com.xixi.canal.client.support.MasterInfo;
import com.xixi.canal.client.support.WriterConfig;
import org.springframework.beans.factory.annotation.Value;

import java.util.List;

@ConfigProperties(prefix = "canal.instance")
public class InstanceConfig {

    private String destination;

    private MasterInfo master;

    private String filter;

    private List<WriterConfig> writers;

    private Integer retries;

    private Integer batchSize;

    private Integer syncBatchSize = 1000;

    @Value("${detecting.enable}")
    private Boolean detectingEnable = false;

    @Value("${detecting.sql}")
    private String detectingSql = "select 1";

    @Value("${detecting.retry.threshold}")
    private Integer detectingRetryThreshold = 3;

    @Value("${detecting.interval.time}")
    private Integer detectingIntervalTime = 5;

    @Value("${detecting.heartbeatHaEnable}")
    private Boolean detectingHeartbeatHaEnable = false;

    @Value("${memory.buffer.size}")
    private Integer memoryBufferSize = 16384;

    @Value("${memory.buffer.memunit}")
    private Integer memoryBufferMemunit = 1024;

    @Value("${memory.batch.mode}")
    private String memoryBatchMode = "MEMSIZE";

    @Value("${memory.rawEntry}")
    private Boolean memoryRawEntry = true;

    @Value("${ddl.isolation}")
    private Boolean ddlIsolation = false;

    @Value("${network.receiveBufferSize}")
    private Integer networkReceiveBufferSize;

    @Value("${network.sendBufferSize}")
    private Integer networkSendBufferSize;

    @Value("${network.soTimeout}")
    private Integer networkSoTimeout;

    @Value("${fallbackIntervalInSeconds}")
    private Integer fallbackIntervalInSeconds;

    @Value("${parser.parallel}")
    private Boolean parallel = true;

    @Value("${parser.transactionSize}")
    private Integer transactionSize = 1024;

    @Value("${gtidEnable}")
    private Boolean gtidEnable = false;

    @Value("${tsdb.enable}")
    private Boolean enableTsdb = true;

    @Value("${tsdb.dir}")
    private String tsdbDir;

    @Value("${tsdb.url}")
    private String tsdbUrl;

    @Value("${tsdb.dbUsername}")
    private String tsdbDbUsername;

    @Value("${tsdb.dbPassword}")
    private String tsdbDbPassword;

    @Value("${tsdb.spring.xml}")
    private String tsdbSpringXml;

    @Value("${tsdb.snapshot.interval}")
    private Integer tsdbSnapshotInterval = 24;

    @Value("${tsdb.snapshot.expire}")
    private Integer tsdbSnapshotExpire = 360;

    @Value("${indexMode}")
    private String indexMode = "MEMORY";

    public String getIndexMode() {
        return indexMode;
    }

    public void setIndexMode(String indexMode) {
        this.indexMode = indexMode;
    }

    public String getDestination() {
        return destination;
    }

    public void setDestination(String destination) {
        this.destination = destination;
    }

    public String getTsdbDir() {
        return tsdbDir;
    }

    public void setTsdbDir(String tsdbDir) {
        this.tsdbDir = tsdbDir;
    }

    public String getTsdbUrl() {
        return tsdbUrl;
    }

    public void setTsdbUrl(String tsdbUrl) {
        this.tsdbUrl = tsdbUrl;
    }

    public String getTsdbDbUsername() {
        return tsdbDbUsername;
    }

    public void setTsdbDbUsername(String tsdbDbUsername) {
        this.tsdbDbUsername = tsdbDbUsername;
    }

    public String getTsdbDbPassword() {
        return tsdbDbPassword;
    }

    public void setTsdbDbPassword(String tsdbDbPassword) {
        this.tsdbDbPassword = tsdbDbPassword;
    }

    public Boolean getEnableTsdb() {
        return enableTsdb;
    }

    public void setEnableTsdb(Boolean enableTsdb) {
        this.enableTsdb = enableTsdb;
    }

    public String getTsdbSpringXml() {
        return tsdbSpringXml;
    }

    public void setTsdbSpringXml(String tsdbSpringXml) {
        this.tsdbSpringXml = tsdbSpringXml;
    }

    public Integer getTsdbSnapshotInterval() {
        return tsdbSnapshotInterval;
    }

    public void setTsdbSnapshotInterval(Integer tsdbSnapshotInterval) {
        this.tsdbSnapshotInterval = tsdbSnapshotInterval;
    }

    public Integer getTsdbSnapshotExpire() {
        return tsdbSnapshotExpire;
    }

    public void setTsdbSnapshotExpire(Integer tsdbSnapshotExpire) {
        this.tsdbSnapshotExpire = tsdbSnapshotExpire;
    }

    public Boolean getGtidEnable() {
        return gtidEnable;
    }

    public void setGtidEnable(Boolean gtidEnable) {
        this.gtidEnable = gtidEnable;
    }

    public Integer getTransactionSize() {
        return transactionSize;
    }

    public void setTransactionSize(Integer transactionSize) {
        this.transactionSize = transactionSize;
    }

    public Boolean getParallel() {
        return parallel;
    }

    public void setParallel(Boolean parallel) {
        this.parallel = parallel;
    }

    public Integer getFallbackIntervalInSeconds() {
        return fallbackIntervalInSeconds;
    }

    public void setFallbackIntervalInSeconds(Integer fallbackIntervalInSeconds) {
        this.fallbackIntervalInSeconds = fallbackIntervalInSeconds;
    }

    public Integer getNetworkReceiveBufferSize() {
        return networkReceiveBufferSize;
    }

    public void setNetworkReceiveBufferSize(Integer networkReceiveBufferSize) {
        this.networkReceiveBufferSize = networkReceiveBufferSize;
    }

    public Integer getNetworkSendBufferSize() {
        return networkSendBufferSize;
    }

    public void setNetworkSendBufferSize(Integer networkSendBufferSize) {
        this.networkSendBufferSize = networkSendBufferSize;
    }

    public Integer getNetworkSoTimeout() {
        return networkSoTimeout;
    }

    public void setNetworkSoTimeout(Integer networkSoTimeout) {
        this.networkSoTimeout = networkSoTimeout;
    }

    public MasterInfo getMaster() {
        return master;
    }

    public void setMaster(MasterInfo master) {
        this.master = master;
    }

    public String getFilter() {
        return filter;
    }

    public void setFilter(String filter) {
        this.filter = filter;
    }

    public List<WriterConfig> getWriters() {
        return writers;
    }

    public void setWriters(List<WriterConfig> writers) {
        this.writers = writers;
    }

    public Integer getRetries() {
        return retries;
    }

    public void setRetries(Integer retries) {
        this.retries = retries;
    }

    public Integer getBatchSize() {
        return batchSize;
    }

    public void setBatchSize(Integer batchSize) {
        this.batchSize = batchSize;
    }

    public Integer getSyncBatchSize() {
        return syncBatchSize;
    }

    public void setSyncBatchSize(Integer syncBatchSize) {
        this.syncBatchSize = syncBatchSize;
    }

    public String getDetectingSql() {
        return detectingSql;
    }

    public void setDetectingSql(String detectingSql) {
        this.detectingSql = detectingSql;
    }

    public Integer getDetectingRetryThreshold() {
        return detectingRetryThreshold;
    }

    public void setDetectingRetryThreshold(Integer detectingRetryThreshold) {
        this.detectingRetryThreshold = detectingRetryThreshold;
    }

    public Integer getDetectingIntervalTime() {
        return detectingIntervalTime;
    }

    public void setDetectingIntervalTime(Integer detectingIntervalTime) {
        this.detectingIntervalTime = detectingIntervalTime;
    }

    public Boolean getDetectingHeartbeatHaEnable() {
        return detectingHeartbeatHaEnable;
    }

    public void setDetectingHeartbeatHaEnable(Boolean detectingHeartbeatHaEnable) {
        this.detectingHeartbeatHaEnable = detectingHeartbeatHaEnable;
    }

    public Integer getMemoryBufferSize() {
        return memoryBufferSize;
    }

    public void setMemoryBufferSize(Integer memoryBufferSize) {
        this.memoryBufferSize = memoryBufferSize;
    }

    public Integer getMemoryBufferMemunit() {
        return memoryBufferMemunit;
    }

    public void setMemoryBufferMemunit(Integer memoryBufferMemunit) {
        this.memoryBufferMemunit = memoryBufferMemunit;
    }

    public String getMemoryBatchMode() {
        return memoryBatchMode;
    }

    public void setMemoryBatchMode(String memoryBatchMode) {
        this.memoryBatchMode = memoryBatchMode;
    }

    public Boolean getMemoryRawEntry() {
        return memoryRawEntry;
    }

    public void setMemoryRawEntry(Boolean memoryRawEntry) {
        this.memoryRawEntry = memoryRawEntry;
    }

    public Boolean getDetectingEnable() {
        return detectingEnable;
    }

    public void setDetectingEnable(Boolean detectingEnable) {
        this.detectingEnable = detectingEnable;
    }

    public Boolean getDdlIsolation() {
        return ddlIsolation;
    }

    public void setDdlIsolation(Boolean ddlIsolation) {
        this.ddlIsolation = ddlIsolation;
    }

    @Override
    public String toString() {
        return "InstanceConfig{" +
                "master=" + master +
                ", filter='" + filter + '\'' +
                ", writers=" + writers +
                ", retries=" + retries +
                ", batchSize=" + batchSize +
                ", syncBatchSize=" + syncBatchSize +
                ", detectingEnable=" + detectingEnable +
                ", detectingSql='" + detectingSql + '\'' +
                ", detectingRetryThreshold=" + detectingRetryThreshold +
                ", detectingIntervalTime=" + detectingIntervalTime +
                ", detectingHeartbeatHaEnable=" + detectingHeartbeatHaEnable +
                ", memoryBufferSize=" + memoryBufferSize +
                ", memoryBufferMemunit=" + memoryBufferMemunit +
                ", memoryBatchMode='" + memoryBatchMode + '\'' +
                ", memoryRawEntry=" + memoryRawEntry +
                '}';
    }
}
